import 'package:common_utils/common_utils.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shenfuhui/config/config.dart';
import 'package:shenfuhui/entity/user_info_entity.dart';
import 'package:shenfuhui/provider/userinfo_provider.dart';
import 'package:shenfuhui/utils/user_utils.dart';
import 'package:shenfuhui/views/dialog_manager.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../http/api.dart';
import '../routers/routers.dart';

class OrderListPage extends StatefulWidget {
  String orderType;

  OrderListPage({Key? key, this.orderType = ""}) : super(key: key);

  @override
  State<OrderListPage> createState() => _OrderListPageState();
}

class _OrderListPageState extends State<OrderListPage> {
  var orderlist = [];
  var productList = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      orderlist.add('');
      orderlist.add('');
      orderlist.add('');
      orderlist.add('');

      productList.add('');
    });
  }

  Widget getOrderItem() {
    return InkWell(
      onTap: () {},
      child: Container(
        margin: EdgeInsets.symmetric(vertical: 10.w, horizontal: 25.w),
        padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
        decoration: BoxDecoration(
          color: (Config.colorWhite),
          borderRadius: BorderRadius.circular(10.w),
        ),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Icon(
                  Icons.local_mall_outlined,
                  size: 32.w,
                  color: Config.colorMain,
                ),
                Padding(
                  padding: EdgeInsets.only(left: 10.w),
                ),
                Expanded(
                  child: Text(
                    "商家名称",
                    style: TextStyle(fontSize: 24.sp),
                  ),
                ),
                Text(
                  "待付款",
                  style: TextStyle(fontSize: 22.sp, color: Colors.red),
                ),
              ],
            ),
            Padding(
              padding: EdgeInsets.only(top: 20.w),
            ),
            Container(
              height: 120.w,
              width: double.infinity,
              child: ListView.builder(
                scrollDirection: Axis.vertical,
                padding: EdgeInsets.symmetric(vertical: 1.w),
                itemCount: productList.length,
                physics: const NeverScrollableScrollPhysics(),
                itemBuilder: (BuildContext context, int index) {
                  return getProductItem();
                },
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 20.w),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Text(
                  "共1件商品",
                  style: TextStyle(fontSize: 22.sp, color: Config.colorText1),
                ),
                Padding(
                  padding: EdgeInsets.only(left: 10.w),
                ),
                Text(
                  "合计：",
                  style: TextStyle(fontSize: 22.sp, color: Config.colorText1),
                ),
                Text(
                  "￥0.00",
                  style: TextStyle(fontSize: 22.sp, color: Colors.red),
                ),
              ],
            ),
            Divider(
              color: Config.colorDivider,
              height: 38.w,
              thickness: 2.w,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Container(
                  margin: EdgeInsets.only(left: 15.w),
                  width: 140.w,
                  height: 46.w,
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () => {
                      // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                      //     transition: TransitionType.inFromRight)
                    },
                    style: ButtonStyle(
                      elevation: MaterialStateProperty.all(0),
                      backgroundColor: MaterialStateProperty.all(Colors.white),
                      shape: MaterialStateProperty.all(
                        RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(24.w),
                        ),
                      ),
                      side: MaterialStateProperty.all(
                        BorderSide(color: Config.colorText3, width: 2.w),
                      ),
                    ),
                    child: Text(
                      '取消订单',
                      style:
                          TextStyle(fontSize: 18.sp, color: Config.colorText3),
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 15.w),
                  width: 140.w,
                  height: 46.w,
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () => {
                      // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                      //     transition: TransitionType.inFromRight)
                    },
                    style: ButtonStyle(
                      elevation: MaterialStateProperty.all(0),
                      backgroundColor: MaterialStateProperty.all(Colors.white),
                      shape: MaterialStateProperty.all(
                        RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(24.w),
                        ),
                      ),
                      side: MaterialStateProperty.all(
                        BorderSide(color: Config.colorText3, width: 2.w),
                      ),
                    ),
                    child: Text(
                      '提醒发货',
                      style:
                          TextStyle(fontSize: 18.sp, color: Config.colorText3),
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 15.w),
                  width: 120.w,
                  height: 46.w,
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () => {
                      // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                      //     transition: TransitionType.inFromRight)
                    },
                    style: ButtonStyle(
                      elevation: MaterialStateProperty.all(0),
                      backgroundColor: MaterialStateProperty.all(Colors.white),
                      shape: MaterialStateProperty.all(
                        RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(24.w),
                        ),
                      ),
                      side: MaterialStateProperty.all(
                        BorderSide(color: Config.colorMain, width: 2.w),
                      ),
                    ),
                    child: Text(
                      '付款',
                      style:
                          TextStyle(fontSize: 18.sp, color: Config.colorMain),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget getProductItem() {
    return Container(
      height: 120.w,
      child: InkWell(
        onTap: () {
          Routes.router.navigateTo(context, Routes.orderDetail,
              transition: TransitionType.inFromRight);
        },
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.only(right: 20.w),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(5),
                child: Image.network(
                  "https://pic1.zhimg.com/v2-6438843a4cbae9184b935a75a5059ac6_1440w.jpg?source=172ae18b",
                  fit: BoxFit.fill,
                  width: 100.w,
                  height: 100.w,
                ),
              ),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                  padding: EdgeInsets.only(top: 8.w),
                ),
                Text(
                  "佳能EOS M1000",
                  softWrap: true,
                  style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
                ),
                Container(
                  width: 540.w,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "1024G",
                        softWrap: true,
                        style: TextStyle(
                            color: (Config.colorText1), fontSize: 20.w),
                      ),
                      Text(
                        "X1",
                        softWrap: true,
                        style: TextStyle(
                            color: (Config.colorText1), fontSize: 20.w),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 12.w),
                ),
                Text(
                  "￥0.00",
                  softWrap: true,
                  style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: EasyRefresh(
        header: const MaterialHeader(),
        footer: const MaterialFooter(),
        onRefresh: () async {
          await Future.delayed(const Duration(seconds: 1), () {
            print('refresh');
          });
        },
        onLoad: () async {
          await Future.delayed(
            const Duration(seconds: 1),
            () {
              print('load');
            },
          );
        },
        child: ListView.builder(
          // shrinkWrap: true,
          // scrollDirection: Axis.vertical,
          // physics: const BouncingScrollPhysics(),
          padding: EdgeInsets.symmetric(vertical: 5.w),
          itemCount: orderlist.length,
          itemBuilder: (BuildContext context, int index) {
            return getOrderItem();
          },
        ),
      ),
    );
  }
}
